package com.gs.gaosheng.controller;

import com.gs.common.annotation.Log;
import com.gs.common.core.controller.BaseController;
import com.gs.common.core.domain.AjaxResult;
import com.gs.common.core.page.TableDataInfo;
import com.gs.common.enums.BusinessType;
import com.gs.common.utils.poi.ExcelUtil;
import com.gs.gaosheng.domain.GsGoods;
import com.gs.gaosheng.service.GsGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品表Controller
 *
 * @author yy
 * @date 2023-08-03
 */
@RestController
@RequestMapping("/gaosheng/goods")
public class GsGoodsController extends BaseController
{
    @Autowired
    private GsGoodsService gsGoodsService;

    /**
     * 查询商品表列表
     */
    @GetMapping("/list")
    public TableDataInfo list(GsGoods gsGoods)
    {
        startPage();
        List<GsGoods> list = gsGoodsService.selectGsGoodsList(gsGoods);
        return getDataTable(list);
    }

    /**
     * 导出商品表列表
     */
    @Log(title = "商品表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GsGoods gsGoods)
    {
        List<GsGoods> list = gsGoodsService.selectGsGoodsList(gsGoods);
        ExcelUtil<GsGoods> util = new ExcelUtil<GsGoods>(GsGoods.class);
        return util.exportExcel(list, "goods");
    }

    /**
     * 获取商品表详细信息
     */
    @GetMapping(value = "/{goodsId}")
    public AjaxResult getInfo(@PathVariable("goodsId") Long goodsId)
    {
        return AjaxResult.success(gsGoodsService.selectGsGoodsById(goodsId));
    }

    /**
     * 新增商品表
     */
    @Log(title = "商品表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GsGoods gsGoods)
    {
        return toAjax(gsGoodsService.insertGsGoods(gsGoods));
    }

    /**
     * 修改商品表
     */
    @Log(title = "商品表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GsGoods gsGoods)
    {
        return toAjax(gsGoodsService.updateGsGoods(gsGoods));
    }

    /**
     * 删除商品表
     */
    @Log(title = "商品表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodsIds}")
    public AjaxResult remove(@PathVariable Long[] goodsIds)
    {
        return toAjax(gsGoodsService.deleteGsGoodsByIds(goodsIds));
    }
}
